package test;

import java.util.ArrayList;
import java.util.List;

public class MovingAverage {
    int size;
    List list = new ArrayList<Integer>();
    public MovingAverage(int size) {
        this.size = size;
    }
    public double next(int val) {
        list.add(val);
        int sum = 0;
        for(int i = Math.max(0, list.size() - size); i < list.size(); ++i)
            sum += (int)list.get(i);
        return sum * 1.0 / Math.min(list.size(), size);
    }
}
